# -*- coding: utf-8 -*-

import requests
import json
import urllib
import re
import random 
import warnings
warnings.filterwarnings("ignore")
from multiprocessing import Pool
from multiprocessing.dummy import Pool
from selenium import webdriver
import datetime
import time


def getDetails(keyword,pagesum,cookies):

	''' 淘宝商品搜索查询 '''

	# 获取必要cookies
	# driver = webdriver.PhantomJS()
	# driver.maximize_window()
	# driver.get('https://www.taobao.com/')  # 地址栏里输入网址
	# cookies = {}
	# cookies_list = driver.get_cookies()
	# for i in cookies_list:
	# 	cookies[i["name"]] = i["value"]
	# driver.close()


	url_head='https://s.taobao.com/search?q='+keyword+'&s='   
	url_list=[url_head+str(i*44) for i in range(0,pagesum)]
 
	for url in url_list:
		resp=requests.get(url,cookies = cookies,verify=False)
		pic_url=re.findall(pattern='"pic_url":"(.*?)"',string=resp.text)  #发货地址
		print (pic_url)
		time.sleep(random.uniform(0.5, 2))
 




if __name__ == '__main__':

	keyword = '男装'
	pagesum = 10
	cookie = {"v":"0","uc3":"vt3=F8dByR%2FPtXkmfFoC5kg%3D&id2=UNN0nnQ5PzBj6g%3D%3D&nk2=sHmGuBnK6YrEuQ%3D%3D&lg2=VFC%2FuZ9ayeYq2g%3D%3D","lgc":"%5Cu5FA1%5Cu679C%5Cu65D7%5Cu8230%5Cu5E97","mt":"np=","cookie2":"1d550064a7d9ba6964ea2b01e93ed0fa","tracknick":"%5Cu5FA1%5Cu679C%5Cu65D7%5Cu8230%5Cu5E97","_tb_token_":"7e3ed611e7686","_l_g_":"Ug%3D%3D","cookie17":"UNN0nnQ5PzBj6g%3D%3D","skt":"993e321bcb0b192b","sg":"%E5%BA%9702","cookie1":"UNaOmjEdkzPF0d%2BKqRdPBjspDZcJ%2BrbnVjjQlzW63YA%3D","_cc_":"UIHiLt3xSw%3D%3D","unb":"3397628220","JSESSIONID":"7C21ABC06A034934C9F0DA9CF8597CFE","existShop":"MTU0MjAwNzg1NA%3D%3D","csg":"1b8c0a6b","_nk_":"%5Cu5FA1%5Cu679C%5Cu65D7%5Cu8230%5Cu5E97","isg":"BAcHbgdwEHcJIJT75TnuSUulmrLRDNvuAO-pVdn0Ixa9SCcK4dxrPkWK7oYWu7Nm","tg":"0","cna":"15ZiFBhnImkCAcFwhT7OdcJz","dnk":"%5Cu5FA1%5Cu679C%5Cu65D7%5Cu8230%5Cu5E97","t":"516aeb2b9d6d3cd31488741688bcca95","uc1":"cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&tmb=1&cookie21=UIHiLt3xSard&cookie15=V32FPkk%2Fw0dUvg%3D%3D&existShop=true&pas=0&cookie14=UoTYNO8Rz%2BPKkQ%3D%3D&tag=8&lng=zh_CN"}
	getDetails(keyword,pagesum,cookie)